<template>
  <div class="user">
    <div class="head-page" v-if="isLogin">
      <div class="head-img">
        <img src="@/assets/default-avatar.png" alt="" />
      </div>
      <div class="info">
        <div class="mobile">{{ detail || 0 }}</div>
        <div class="vip">
          <van-icon name="diamond-o" />
          普通会员
        </div>
      </div>
    </div>

    <div v-else class="head-page" @click="$router.push('/login')">
      <div class="head-img">
        <img src="@/assets/default-avatar.png" alt="" />
      </div>
      <div class="info">
        <div class="mobile">未登录</div>
        <div class="words">点击登录账号</div>
      </div>
    </div>

    <div class="my-asset">
      <div class="asset-left">
        <div class="asset-left-item" @click="alert">
          <div class="svg">
            <img :src="dp" alt="">
          </div>
          <span>电影票</span>
        </div>
        <div class="asset-left-item" @click="alert">
           <div class="svg">
            <img :src="pj" alt="">
          </div>
          <span>演出票</span>
        </div>
        <div class="asset-left-item" @click="alert">
           <div class="svg">
            <img :src="food" alt="">
          </div>
          <span>小食/其他</span>
        </div>
      </div>
    </div>

    <div class="service">
      <div class="title">我的服务</div>
      <div class="content">
        <div class="content-item">
        <van-icon name="notes-o" />
          <span>特惠专区</span>
        </div>
        <div class="content-item" @click="alert">
         <van-icon name="star-o" />
          <span>我的收藏</span>
        </div>
        <div class="content-item" @click="alert">
          <van-icon name="gift-card-o" />
          <span>优惠券</span>
        </div>
        <div class="content-item" @click="alert">
         <van-icon name="vip-card-o" />
          <span>权益卡</span>
        </div>
        <div class="content-item" @click="alert">
          <van-icon name="friends-o" />
          <span>观演人</span>
        </div>
        <div class="content-item" @click="alert">
         <van-icon name="location-o" />
          <span>收货地址</span>
        </div>
          <div class="content-item" @click="alert">
             <van-icon name="smile-o" />
          <span>我的小剧场</span>
        </div>
         <div class="content-item" @click="alert">
             <van-icon name="chat-o" />
          <span>用户反馈</span>
        </div>
      </div>
    </div>
       <div class="logout-btn">
     <button @click="logout">退出登录</button>
    </div>
  <!-- 图片 -->
   <div v-if="!$store.getters.token" class="foot-admin">
     <van-empty image-size="220"  :image="foot_img" description="描述文字" >
      <template #description>
         <span class="b1">开启我的淘票票时光</span>
         <span class="b2">标记想看，完成评价</span>
         <span class="b2">即可开启我的淘票票时光</span>
      </template>
      </van-empty>
   </div>

   <div v-else>
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="(item,index) in imglist" :key="index">
          <img :src="item.url" alt="">
        </van-swipe-item>
      </van-swipe>
      <div class="movielist">
        <div v-show="list.length" class="foot">已购买电影</div>
           <div v-if="list.length">
             <div
                @click="$router.push(`/prodetail/?name=${ele.name}`)"
                class="movietext" v-for="(ele,index) in list" :key="index">
                    <!-- 左 -->
                <div class="left">
                        <img :src="ele.img" alt="">
                    </div>
                    <!-- 中 -->
                    <div class="center">
                        <div class="center-header">{{ele.name}}</div>
                        <div v-if="ele.flag" class="center-header2">
                            <span  style="font-size: 3.1vw;">淘票票评分</span>
                            <span style="font-size:3.4vw;color:rgb(244, 138, 16);margin-left:1vw">{{ele.score}}</span>
                        </div>
                        <div class="center-header2">
                            <span style="font-size:3.4vw;color:rgb(244, 138, 16);margin-left:1vw">{{ele.number2}}</span>
                            <span style="font-size: 3.1vw;margin-right:2vw;margin-left:1vw;">想看</span>
                            <span style="font-size: 3.1vw;color:#999">|</span>
                            <span style="font-size: 3.1vw; margin-left:2vw">{{ele.time2}}</span>
                        </div>
                        <div class="center-header3">
                            <span style="font-size: 3.1vw;">导演:</span>
                            <span style="font-size: 3.1vw;margin-left:1vw;">{{ele.actor[0].name}}</span>
                        </div>
                        <div class="center-header3">
                            <span style="font-size: 3.1vw;">主演:</span>
                            <span v-for="(item,index2) in ele.actor.slice(1)" :key="index2"  style="font-size: 3.1vw;margin-left:1vw;">{{item.name}}</span>
                        </div>
                    </div>
                    <!-- 右 -->
                    <div class="right">
                        <van-button @click="ByMovie(index)"  round size="small" color="linear-gradient(to right, #ff6034, #ee0a24)" type="info">待观影</van-button>
                    </div>
            </div>
           </div>
           <div v-else>
            <van-empty description="当前还未购买电影" >
               <van-button @click="$router.push('/movie')" style="width:35vw" round type="danger" class="bottom-button">去逛逛</van-button>
              </van-empty>
           </div>
      </div>
   </div>
  </div>
</template>

<script>
import { getDetailInfolist } from '@/api/detail'
export default {
  name: 'UserPage',
  data () {
    return {
      detail: this.$store.state.user.userInfo.userId,
      dp: require('@/assets/电影.png'),
      pj: require('@/assets/暂无票券.png'),
      food: require('@/assets/爆米花.png'),
      foot_img: require('@/assets/保障.png'),
      imglist: [
        { url: require('@/assets/lbz.jpg') },
        { url: require('@/assets/lbz.jpg') },
        { url: require('@/assets/lbz.jpg') },
        { url: require('@/assets/lbz.jpg') }
      ],
      list: []
    }
  },
  created () {
    this.getlist()
  },
  computed: {
    isLogin () {
      return this.$store.getters.token
    }
  },
  methods: {
    getlist () {
      const res = getDetailInfolist()
      // this.list = res.filter(ele => ele.buy === true)
      this.list = res
    },
    logout () {
      if (!this.$store.state.user.userInfo.userId) {
        this.$toast('请先登录')
      } else {
        this.$dialog.confirm({
          title: '温馨提示',
          message: '你确认要退出么？'
        })
          .then(() => {
            this.$store.dispatch('user/logout')
            this.$toast('退出成功')
          })
          .catch(() => {

          })
      }
    },
    alert () {
      this.$toast({
        message: '开发中·····',
        duration: 1000
      })
    }
  }
}
</script>

<style lang="less" scoped>
.user {
  min-height: 100vh;
  background-color: #f7f7f7;
  padding-bottom: 50px;
}

.head-page {
  height: 130px;
  background: url("http://cba.itlike.com/public/mweb/static/background/user-header2.png");
  background-size: cover;
  display: flex;
  align-items: center;
  .head-img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    margin: 0 10px;
    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
}
.info {
  .mobile {
    margin-bottom: 5px;
    color: #c59a46;
    font-size: 18px;
    font-weight: bold;
  }
  .vip {
    display: inline-block;
    background-color: #3c3c3c;
    padding: 3px 5px;
    border-radius: 5px;
    color: #e0d3b6;
    font-size: 14px;
    .van-icon {
      font-weight: bold;
      color: #ffb632;
    }
  }
}

.my-asset {
  display: flex;
  padding: 20px 0;
  font-size: 14px;
  background-color: #fff;
  .asset-left {
    display: flex;
    justify-content: space-evenly;
    flex: 3;
    .asset-left-item {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      .svg{
        width: 15vw;
        height: 15vw;
        padding-bottom: 2vw;
        img{
          width: 100%;
          height: 100%;
          // background-color: red;
        }
      }
      span:first-child {
        margin-bottom: 5px;
        color: #ff0000;
        font-size: 16px;
      }
    }
  }
}
.service {
  font-size: 14px;
  background-color: #fff;
  border-radius: 5px;
  margin: 10px;
  .title {
    height: 50px;
    line-height: 50px;
    padding: 0 15px;
    font-size: 16px;
  }
  .content {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    font-size: 14px;
    background-color: #fff;
    border-radius: 5px;
    .content-item {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 25%;
      margin-bottom: 20px;

      .van-icon {
        font-size: 26px;
        margin-bottom: 5px;
        color: #ed27b1;
      }
    }
  }
}
.foot-admin{
  width: 95%;
  // height: 70vw;
  margin: 10px auto;
  border-radius: 5px;
  background-color: #fff;
  .b1{
    display: inline-block;
    width: 100%;
    text-align: center;
    font-size: 4.7vw;
    color: #000;
    margin-bottom: 3vw;
  }
  .b2{
    display: inline-block;
    width: 100%;
    text-align: center;
    // margin-bottom: 1vw;
  }
}
.logout-btn {
  button {
    width: 60%;
    margin: 10px auto;
    margin-bottom: 3.7vw;
    display: block;
    font-size: 13px;
    color: #616161;
    border-radius: 9px;
    border: 1px solid #dcdcdc;
    padding: 7px 0;
    text-align: center;
    background-color: #fafafa;
  }
}
 .my-swipe .van-swipe-item {
    color: #fff;
    font-size: 20px;
    line-height: 3vw;
    text-align: center;
    img{
      width: 100%;
      height: 100%;
    }
  }
  .movietext{
    width: 100%;
    padding: 3vw;
    display: flex;
    justify-content: space-between;
    background-color: #fff;
    border-radius: 3vw;
    margin-top: 3vw;
    .left{
        width: 26%;
        height: 30vw;
        // linear-gradient(to right, #74dbf3, #26a6ea)
        img{
            width: 100%;
            height: 100%;
            border-radius: 2.7vw;
        }
    }
    .center{
        width: 55%;
        height: 33vw;
        padding: 0 2.5vw;
        .center-header{
            font-size: 5.1vw;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
         .center-header2{
            margin-top: 2vw;
            letter-spacing: 0.2vw;
            color: #585656;
            //文字超出隐藏
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
       .center-header3{
            margin-top: 1vw;
            letter-spacing: 0.2vw;
            color: #585656;
            // 文字溢出隐藏
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    }
    .right{
        width: 19%;
        height: 12vw;
        margin-top: 8vw;
        ::v-deep .van-button__content{
            width: 13vw;
            letter-spacing: 0.6vw;
        }
    }
}
.foot{
  width: 30vw;
  margin: 3vw auto;
  font-size: 5.1vw;
}
</style>
